package com.taobao.txc.parser.b.c;

import com.a.a.a.a.a.c;
import com.a.a.a.a.c.c.n;
import com.a.a.a.a.c.c.r;
import com.a.a.a.a.c.c.t;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.TxcContext;
import com.taobao.txc.parser.b.a.e;
import com.taobao.txc.parser.struct.TxcField;
import com.taobao.txc.parser.struct.TxcLine;
import com.taobao.txc.parser.struct.TxcTable;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;

public class i
  extends a
  implements e
{
  private static final LoggerWrap i = LoggerInit.logger;
  
  public i(k paramk)
  {
    super(paramk);
  }
  
  private n m()
  {
    com.a.a.a.a.c.a locala = ((k)j()).e();
    if ((locala instanceof t)) {
      locala = (com.a.a.a.a.c.a)((t)locala).c().get(0);
    }
    return (n)locala;
  }
  
  public void a(n paramn) {}
  
  public String l()
  {
    n localn = m();
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append(c(localn));
    c localc1 = localn.g();
    localStringBuilder.append(a(localc1, null));
    com.a.a.a.a.b.a locala = localn.m();
    localStringBuilder.append(b(locala));
    c localc2 = localn.n();
    localStringBuilder.append(b(localc2));
    com.a.a.a.a.b.d locald = localn.h();
    localStringBuilder.append(b(locald));
    com.a.a.a.a.b.b localb = localn.i();
    localStringBuilder.append(b(localb));
    localStringBuilder.append(b(localn));
    if (i.c()) {
      i.debug(localStringBuilder.toString());
    }
    return localStringBuilder.toString();
  }
  
  public String k()
  {
    return l();
  }
  
  public String d(com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    n localn = m();
    StringBuilder localStringBuilder = new StringBuilder();
    c localc1 = localn.g();
    localStringBuilder.append(a(localc1, null));
    com.a.a.a.a.b.a locala = localn.m();
    localStringBuilder.append(b(locala));
    c localc2 = localn.n();
    localStringBuilder.append(b(localc2));
    com.a.a.a.a.b.d locald = localn.h();
    localStringBuilder.append(b(locald));
    com.a.a.a.a.b.b localb = localn.i();
    localStringBuilder.append(b(localb));
    localStringBuilder.append(b(localn));
    return localStringBuilder.toString();
  }
  
  public TxcTable b(com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    a(i());
    return c();
  }
  
  public TxcTable c(com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    b(i());
    return d();
  }
  
  String b(n paramn)
  {
    StringBuilder localStringBuilder = h();
    r localr = paramn.l();
    switch (j.a[localr.h.ordinal()])
    {
    case 1: 
      localStringBuilder.append(" FOR UPDATE");
      break;
    case 2: 
      localStringBuilder.append(" LOCK IN SHARE MODE");
      break;
    case 3: 
      break;
    default: 
      throw new IllegalArgumentException("unknown option for SELECT: " + localr);
    }
    return localStringBuilder.toString();
  }
  
  String b(com.a.a.a.a.b.b paramb)
  {
    StringBuilder localStringBuilder = h();
    if (paramb != null)
    {
      localStringBuilder.append(' ');
      paramb.a(this);
    }
    return localStringBuilder.toString();
  }
  
  String b(com.a.a.a.a.b.d paramd)
  {
    StringBuilder localStringBuilder = h();
    if (paramd != null)
    {
      localStringBuilder.append(' ');
      paramd.a(this);
    }
    return localStringBuilder.toString();
  }
  
  String b(c paramc)
  {
    StringBuilder localStringBuilder = h();
    if (paramc != null)
    {
      localStringBuilder.append(" HAVING ");
      paramc.a(this);
    }
    return localStringBuilder.toString();
  }
  
  String b(com.a.a.a.a.b.a parama)
  {
    StringBuilder localStringBuilder = h();
    if (parama != null)
    {
      localStringBuilder.append(' ');
      parama.a(this);
    }
    return localStringBuilder.toString();
  }
  
  String c(n paramn)
  {
    StringBuilder localStringBuilder = h();
    localStringBuilder.append("SELECT ");
    r localr = paramn.l();
    switch (j.b[localr.a.ordinal()])
    {
    case 1: 
      break;
    case 2: 
      localStringBuilder.append("DISTINCT ");
      break;
    case 3: 
      localStringBuilder.append("DISTINCTROW ");
      break;
    default: 
      throw new IllegalArgumentException("unknown option for SELECT: " + localr);
    }
    if (localr.b) {
      localStringBuilder.append("HIGH_PRIORITY ");
    }
    if (localr.c) {
      localStringBuilder.append("STRAIGHT_JOIN ");
    }
    switch (j.c[localr.d.ordinal()])
    {
    case 1: 
      localStringBuilder.append("SQL_BIG_RESULT ");
      break;
    case 2: 
      localStringBuilder.append("SQL_SMALL_RESULT ");
      break;
    case 3: 
      break;
    default: 
      throw new IllegalArgumentException("unknown option for SELECT: " + localr);
    }
    if (localr.e) {
      localStringBuilder.append("SQL_BUFFER_RESULT ");
    }
    switch (j.d[localr.f.ordinal()])
    {
    case 1: 
      localStringBuilder.append("SQL_CACHE ");
      break;
    case 2: 
      localStringBuilder.append("SQL_NO_CACHE ");
      break;
    case 3: 
      break;
    default: 
      throw new IllegalArgumentException("unknown option for SELECT: " + localr);
    }
    if (localr.g) {
      localStringBuilder.append("SQL_CALC_FOUND_ROWS ");
    }
    int j = 1;
    List localList = paramn.e();
    Object localObject = localList.iterator();
    while (((Iterator)localObject).hasNext())
    {
      com.a.a.a.c.b localb = (com.a.a.a.c.b)((Iterator)localObject).next();
      if (j != 0) {
        j = 0;
      } else {
        localStringBuilder.append(", ");
      }
      if ((localb.a() instanceof n)) {
        localStringBuilder.append("(");
      }
      ((c)localb.a()).a(this);
      if ((localb.a() instanceof n)) {
        localStringBuilder.append(")");
      }
      String str = (String)localb.b();
      if (str != null) {
        localStringBuilder.append(" AS ").append(str);
      }
    }
    localObject = paramn.f();
    if (localObject != null)
    {
      localStringBuilder.append(" FROM ");
      localStringBuilder.append(j().b());
    }
    return localStringBuilder.toString();
  }
  
  String a(c paramc, String paramString)
  {
    StringBuilder localStringBuilder = h();
    if (paramc != null)
    {
      localStringBuilder.append(" WHERE ");
      paramc.a(this);
      if ((paramString != null) && (!paramString.isEmpty()))
      {
        localStringBuilder.append(" AND ");
        localStringBuilder.append(paramString);
      }
    }
    else if ((paramString != null) && (!paramString.isEmpty()))
    {
      localStringBuilder.append(" WHERE ");
      localStringBuilder.append(paramString);
    }
    return localStringBuilder.toString();
  }
  
  public String d(TxcTable paramTxcTable)
  {
    if (paramTxcTable == null) {
      throw new SQLException("table is not exit");
    }
    com.taobao.txc.parser.struct.k localk = f();
    if (localk == null) {
      throw new SQLException("tableMeta is null");
    }
    String str1 = localk.h();
    if (StringUtils.isEmpty(str1)) {
      throw new SQLException("pkName is null");
    }
    List localList = paramTxcTable.c();
    n localn = m();
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append(c(localn));
    if (paramTxcTable.b() != 0)
    {
      localStringBuilder.append(" WHERE ");
      localStringBuilder.append(str1);
      localStringBuilder.append(" IN (");
      int j = 0;
      Iterator localIterator1 = localList.iterator();
      while (localIterator1.hasNext())
      {
        TxcLine localTxcLine = (TxcLine)localIterator1.next();
        Iterator localIterator2 = localTxcLine.a().iterator();
        while (localIterator2.hasNext())
        {
          TxcField localTxcField = (TxcField)localIterator2.next();
          if (localTxcField.b(str1))
          {
            if (j != 0) {
              localStringBuilder.append(",");
            } else {
              j = 1;
            }
            localStringBuilder.append(localTxcField.c());
          }
        }
      }
      localStringBuilder.append(")");
    }
    else
    {
      localStringBuilder.append(" WHERE 1=0");
    }
    String str2 = localStringBuilder.toString();
    i.info(String.format("[xid:%d] [%s]", new Object[] { Long.valueOf(TxcContext.d()), str2 }));
    return str2;
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.parser.b.c.i
 * JD-Core Version:    0.7.0.1
 */